set more 1

/*
File:	cepr_basic_family.do
Date:	Nov 21, 2006
	Feb 15, 2008
	Feb 10, 2009
	Jan 4, 2010
	Feb 22, 2011
	Mar 21, 2011 CEPR ORG Version 1.6.1
	Jan 3, 2012 CEPR ORG Version 1.7
	Jan 3, 2013
	Dec 20, 2013
	Mar 12, 2015, CEPR ORG Version 2.0
	Apr  1, 2015, CEPR ORG Version 2.0.1
	March 1, 2016, CEPR ORG Version 2.1
	Oct 12, 2016, CEPR ORG Version 2.1.1
	Feb 9, 2017, CEPR ORG Version 2.2
	Apr 21, 2017, CEPR ORG Version 2.2.1
	Apr 10, 2018, CEPR ORG Version 2.3
	Mar 22, 2019, CEPR ORG Version 2.4
	Jul 24, 2019, CEPR ORG Version 2.4.1
	Feb 05, 2020, CEPR ORG Version 2.5
	
Desc:	Creates consistent family-relationship variables for CEPR consistent
	extract	of Basic CPS
Note:	See copyright notice at end of program.
*/

/* note: any pre-1994 data processing is not yet correct;
         use only to process data from 1994 forward
*/

/* Determine data year */
local year=year in 1

/* Marital status - Dummy */

gen byte married=.

if `year'==1991 {
replace married=0 if 1<=admaritl & admaritl<=7
replace married=1 if 1<=admaritl & admaritl<=3
}
if 1994<=`year' & `year'<=2020 {
replace married=0 if prmarsta~=.
replace married=1 if 1<=prmarsta & prmarsta<=3
}
lab var married "Married"
notes married: CPS: derived from prmarsta, a-maritl

/* Marital Status */

if 1994<= `year' & `year'<=2020 {
gen byte marstat=0 if prmarsta~=.
replace marstat=1 if 1<=prmarsta & prmarsta<=3
replace marstat=2 if prmarsta==4
replace marstat=3 if prmarsta==5
replace marstat=4 if prmarsta==6
replace marstat=5 if prmarsta==7
}
lab var marstat "Marital status"
#delimit;
lab define marstat 
1 "Married"
2 "Widowed"
3 "Divorced"
4 "Separated"
5 "Never Married"
;
#delimit cr
lab val marstat marstat
notes marstat: CPS: derived: a-maritl, prmarsta

gen byte ownchild=.

if 1979<=`year' & `year'<=1983 {
/* Not available in survey */
}
if `year'==1991 {
replace ownchild=0 if adpfnocd==1 /* no children */
replace ownchild=1 if adpfnocd==2
replace ownchild=2 if adpfnocd==3
replace ownchild=3 if adpfnocd==4
replace ownchild=4 if adpfnocd==5
replace ownchild=5 if adpfnocd==6
replace ownchild=6 if adpfnocd==7
replace ownchild=7 if adpfnocd==8
replace ownchild=8 if adpfnocd==9 /* 8+ children */
}
if 1994<=`year' & `year'<=1999 {
/* Not available in survey */
}
if 2000<=`year' & `year'<=2009 {
replace ownchild=prnmchld
replace ownchild=. if prnmchld<0
replace ownchild=. if (prfamrel~=1 & prfamrel~=2)
}
if 2010<=`year' & `year'<=2020 {
replace ownchild=prnmchld
/* recode non-reference person, non-spouse to missing
for consistency with earlier years */
replace ownchild=. if (prfamrel~=1 & prfamrel~=2)
replace ownchild=. if prnmchld<0
}
lab var ownchild "Number of children"
notes ownchild: Number of own children under 18 in primary family
notes ownchild: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years
notes ownchild: 1991: top-code=8
notes ownchild: Not available in CPS for years 1994 to 1999
notes ownchild: Available 1984-93 and 2000- only
notes ownchild: CPS: derived from prnmchld, a-pfnocd

/* Presence of own child, by child's age */

gen byte ch02=.
gen byte ch05=.
gen byte ch35=.
gen byte ch613=.
gen byte ch1417=.

if `year'==1991 {
replace ch02=0 if 0<adpfprcd
replace ch02=1 if adpfprcd==2 | (6<=adpfprcd & adpfprcd<=8) | /*
*/ (12<=adpfprcd & adpfprcd<=14) | adpfprcd==16
*
replace ch05=0 if 0<adpfprcd
replace ch05=1 if adpfprcd==2 | adpfprcd==3 | (6<=adpfprcd & adpfprcd<=10) /*
*/ | (12<=adpfprcd & adpfprcd<=16)
*
replace ch35=0 if 0<adpfprcd
replace ch35=1 if adpfprcd==3 | adpfprcd==6 | adpfprcd==9 | adpfprcd==10 | /*
*/ adpfprcd==12 | adpfprcd==13 | adpfprcd==15 | adpfprcd==16
*
replace ch613=0 if 0<adpfprcd
replace ch613=1 if adpfprcd==4 | adpfprcd==7 | adpfprcd==9 | adpfprcd==11 | /*
*/ adpfprcd==12 | (14<=adpfprcd & adpfprcd<=16)
*
replace ch1417=0 if 0<adpfprcd
replace ch1417=1 if adpfprcd==5 | adpfprcd==8 | adpfprcd==10 | adpfprcd==11 /*
*/ | (13<=adpfprcd & adpfprcd<=16)
}
if 2000<=`year' & `year'<=2009 {
* prchld not available before 2000
*

/* recode non-reference person, non-spouse to missing
for consistency with earlier years */
replace prchld=. if (prfamrel~=1 & prfamrel~=2)
*
replace ch02=0 if 0<=prchld & prchld~=.
replace ch02=1 if prchld==1 | (5<=prchld & prchld<=7) | prchld==11 | /*
*/ prchld==12 | prchld==13 | prchld==15
*
replace ch05=0 if 0<=prchld & prchld~=.
replace ch05=1 if prchld==1 | prchld==2 | (5<=prchld & prchld<=9) | /*
*/ (11<=prchld &  prchld<=15)
*
replace ch35=0 if 0<=prchld & prchld~=.
replace ch35=1 if prchld==2 | prchld==5 | prchld==8 | prchld==9 | /*
*/ prchld==11 | prchld==12 | prchld==14 | prchld==15
*
replace ch613=0 if 0<=prchld & prchld~=.
replace ch613=1 if prchld==3 | prchld==6 | prchld==8 | prchld==10 | /*
*/ prchld==11 | (13<=prchld & prchld<=15)
*
replace ch1417=0 if 0<=prchld & prchld~=.
replace ch1417=1 if prchld==4 | prchld==7 | prchld==9 | prchld==10 | /*
*/ (12<=prchld & prchld<=15)
}
if 2010<=`year' & `year'<=2020 {

/* recode non-reference person, non-spouse to missing
for consistency with earlier years */
replace prchld=. if (prfamrel~=1 & prfamrel~=2)
*
replace ch02=0 if 0<=prchld & prchld~=.
replace ch02=1 if prchld==1 | (5<=prchld & prchld<=7) | prchld==11 | /*
*/ prchld==12 | prchld==13 | prchld==15
*
replace ch05=0 if 0<=prchld & prchld~=.
replace ch05=1 if prchld==1 | prchld==2 | (5<=prchld & prchld<=9) | /*
*/ (11<=prchld &  prchld<=15)
*
replace ch35=0 if 0<=prchld & prchld~=.
replace ch35=1 if prchld==2 | prchld==5 | prchld==8 | prchld==9 | /*
*/ prchld==11 | prchld==12 | prchld==14 | prchld==15
*
replace ch613=0 if 0<=prchld & prchld~=.
replace ch613=1 if prchld==3 | prchld==6 | prchld==8 | prchld==10 | /*
*/ prchld==11 | (13<=prchld & prchld<=15)
*
replace ch1417=0 if 0<=prchld & prchld~=.
replace ch1417=1 if prchld==4 | prchld==7 | prchld==9 | prchld==10 | /*
*/ (12<=prchld & prchld<=15)
}

lab var ch02 "Child 0-2"
notes ch02: Available 1989-93 and 2000- only
notes ch02: CPS: derived from prchld, a-pfprcd
notes ch02: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years

lab var ch05 "Child 0-5"
notes ch05: Available 1984-93 and 2000- only
notes ch05: CPS: derived from prchld, a-pfprcd
notes ch05: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years

lab var ch35 "Child 3-5"
notes ch35: Available 1989-93 and 2000- only
notes ch35: CPS: derived from prchld, a-pfprcd
notes ch35: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years

lab var ch613 "Child 6-13"
notes ch613: Available 1984-93 and 2000- only
notes ch613: CPS: derived from prchld, a-pfprcd
notes ch613: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years

lab var ch1417 "Child 14-17"
notes ch1417: Available 1984-93 and 2000- only
notes ch1417: CPS: derived from prchld, a-pfprcd
notes ch1417: Undocumented change starting with 2010 that has /*
*/ responses for repondents who are not the ref person or spouse, /*
*/ so set non-ref person/non-spouse to missing for consistency /*
*/ with earlier years

/* Family relationship */

gen byte famrel84=.
gen byte famrel94=.
gen byte famrel=.

/*
if 1984<=`year' & `year'<=1993 {
*
gen byte famrel84=pfamrel
replace famrel84=6 if pfamrel==0
*
replace famrel=1 if 1<=pfamrel & pfamrel<=2
replace famrel=2 if pfamrel==3
replace famrel=3 if pfamrel==4
replace famrel=1 if pfamrel==5
replace famrel=4 if pfamrel==0
}
*/
if `year'==1991 {
replace famrel84=.
*
replace famrel94=adfamrel
replace famrel94=5 if adfamrel==0
*
replace famrel=1 if 1<=famrel94 & famrel94<=2
replace famrel=2 if famrel94==3
replace famrel=3 if famrel94==4
replace famrel=4 if famrel94==5
}
if 1994<=`year' & `year'<=2020 {
*
replace famrel94=prfamrel
replace famrel94=5 if prfamrel==0
replace famrel94=. if prfamrel==-1

*
replace famrel=1 if 1<=prfamrel & prfamrel<=2 /* reference person or spouse */
replace famrel=2 if prfamrel==3 /* child */
replace famrel=3 if prfamrel==4 /* other relative */
replace famrel=1 if prfamrel==5 /* unmarried reference person */
replace famrel=4 if prfamrel==0 /* not a family member */
}

lab var famrel84 "Family relation"
#delimit ;
lab def fr84
1 "Husband"
2 "Wife"
3 "Own child"
4 "Other relative"
5 "Unmarried reference person"
6 "Not in primary family";
#delimit cr
lab val famrel84 fr84
notes famrel84: Not available 1979-83 or 1994-
notes famrel84: CPS: a-pfamrel

lab var famrel94 "Family relation"
#delimit ;
lab def fr94
1 "Reference person"
2 "Spouse"
3 "Own child"
4 "Other relative"
5 "Not in primary family";
#delimit cr
/* 5 "Unmarried reference person" 
is listed in the NBER documentation for 1994-, but no observations
have a value==5 and the original CPS documentation from 1994 list only
the five categories in label fr94
*/
lab val famrel94 fr94
notes famrel94: Not available 1979-83
notes famrel94: CPS: prfamrel, a-famrel
notes famrel94: for 94-on, made -1 = missing

lab var famrel "Family relation"
#delimit ;
lab def fr
1 "Head, spouse, or unmarried reference person"
2 "Own child"
3 "Other relative"
4 "Not in primary family";
#delimit cr
lab val famrel fr
notes famrel: Not available 1979-83
notes famrel: CPS: prfamrel, a-pfamrel, a-famrel

/* Head of Household */

if 1989<=`year' & `year'<=2020 {
gen byte relahh=.
}

gen hoh79=0
if 1979<=`year' & `year'<=1983 {
replace hoh79=1 if (1<=relahh & relahh<=3)
}
if 1984<=`year' & `year'<=2020 {
replace hoh79=1 if famrel==1
}

notes hoh79: CPS: prfamrel a-pfamrel relah

/* Reference person */

gen byte refper=.

if 1994<=`year' & `year'<=2020 {
replace refper=0 if prfamrel~=.
replace refper=1 if prfamrel==1
}

lab var refper "Reference person"
notes refper: Available 1994-
notes refper: CPS: prfamrel

/* Family income, by income bands 

"(COMBINED INCOME OF ALL FAMILY MEMBERS
DURING THE LAST 12 MONTHS. INCLUDES
MONEY FROM JOBS, NET INCOME FROM
BUSINESS, FARM OR RENT, PENSIONS,
DIVIDENDS, INTEREST, SOCIAL SECURITY
PAYMENTS AND ANY OTHER MONEY INCOME
RECEIVED BY FAMILY MEMBERS WHO ARE 15
YEARS OF AGE OR OLDER.)"

Census Note:Caution should be used when using this variable since it 
				has an allocation rate of approximately 20 percent.
*/

gen byte faminc=.

if `year'==1991 {
replace faminc=hdfaminc+1
replace faminc=. if hdfaminc<0 | hdfaminc==19
}
if 1994<=`year' & `year'<=2002 {
replace faminc=hufaminc
replace faminc=. if hufaminc<0
}
if 2003<=`year' & `year'<=2009 {
replace faminc=hufaminc
*replace faminc=14 if faminc==15 | faminc==16
replace faminc=. if hufaminc<0
}
if 2010<=`year' & `year'<=2020 {
replace faminc=hefaminc
*replace faminc=14 if faminc==15 | faminc==16
replace faminc=. if hefaminc<0
}
lab var faminc "Family income band"
#delimit ;
lab def faminc 
1 "<5000"
2 "5000-7499"
3 "7500-9999"
4 "10000-12499"
5 "12500-14999"
6 "15000-19999"
7 "20000-24999"
8 "25000-29999"
9 "30000-34999"
10 "35000-39999"
11 "40000-49999"
12 "50000-59999"
13 "60000-74999"
14 "75000+ / 75000-99,999"
15 "100000-149999"
16 "150000+"
;
#delimit cr
lab val faminc faminc
notes faminc: Current dollars
notes faminc: Combined income of all family members during the last 12 /*
*/ months. Includes money from jobs, net income from business, farm or /*
*/ rent, pensions, dividends, interest, social security payments and any /*
*/ other money income received by family members who are 15 years of age /*
*/ or older
notes faminc: Not completely consistent: categories 15 and 16 not available /*
*/ in all years
notes faminc: CPS: hufaminc, h-faminc
notes faminc: Census: caution should be used when using this variable, as it /*
*/ has a high allocation rate of approx. 20 percent

/* 
Copyright 2020 CEPR and John Schmitt

This file is part of the cepr_org_master.do program. This file and all
programs referenced in it are free software. You can redistribute the
program or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA.
*/

